home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / base / module.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-28  |  16.0 KB  |  590 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import re
  6. import getopt
  7. import os
  8. from g import *
  9. import tui
  10. import utils
  11. import device
  12. USAGE_FLAG_NONE = 0
  13. USAGE_FLAG_DEVICE_ARGS = 1
  14. USAGE_FLAG_SUPRESS_G_DEBUG_FLAG = 2
  15. USAGE_FLAG_FILE_ARGS = 4
  16.  
  17. class Module(object):
  18.     
  19.     def __init__(self, mod, title, version, doc, usage_data = None, avail_modes = None, supported_ui_toolkits = None, run_as_root_ok = False, quiet = False):
  20.         self.mod = mod
  21.         self.title = title
  22.         self.version = version
  23.         self.doc = doc
  24.         self.usage_data = usage_data
  25.         os.umask(31)
  26.         log.set_module(mod)
  27.         self.args = []
  28.         self.quiet = quiet
  29.         self.lock_file = None
  30.         prop.prog = sys.argv[0]
  31.         if os.getenv('HPLIP_DEBUG'):
  32.             log.set_level('debug')
  33.         
  34.         self.avail_modes = avail_modes
  35.         if supported_ui_toolkits is not None:
  36.             self.supported_ui_toolkits = supported_ui_toolkits
  37.             self.num_supported_ui_toolkits = len(self.supported_ui_toolkits)
  38.         else:
  39.             self.supported_ui_toolkits = []
  40.             self.num_supported_ui_toolkits = 0
  41.         self.default_ui_toolkit = sys_conf.get('configure', 'ui-toolkit', 'qt4')
  42.         self.num_installed_ui_toolkits = 0
  43.         self.installed_ui_toolkits = []
  44.         if utils.to_bool(sys_conf.get('configure', 'qt3', '0')):
  45.             self.installed_ui_toolkits.append(UI_TOOLKIT_QT3)
  46.             self.num_installed_ui_toolkits += 1
  47.         
  48.         if utils.to_bool(sys_conf.get('configure', 'qt4', '0')):
  49.             self.installed_ui_toolkits.append(UI_TOOLKIT_QT4)
  50.             self.num_installed_ui_toolkits += 1
  51.         
  52.         self.default_mode = INTERACTIVE_MODE
  53.         self.num_valid_modes = 0
  54.         if self.avail_modes is not None:
  55.             if GUI_MODE in self.avail_modes and prop.gui_build and self.installed_ui_toolkits:
  56.                 self.num_valid_modes += 1
  57.             
  58.             if INTERACTIVE_MODE in self.avail_modes:
  59.                 self.num_valid_modes += 1
  60.             
  61.             if NON_INTERACTIVE_MODE in self.avail_modes:
  62.                 self.num_valid_modes += 1
  63.             
  64.         
  65.         if self.avail_modes is not None:
  66.             if INTERACTIVE_MODE in self.avail_modes:
  67.                 self.default_mode = INTERACTIVE_MODE
  68.             elif NON_INTERACTIVE_MODE in self.avail_modes:
  69.                 self.default_mode = NON_INTERACTIVE_MODE
  70.             
  71.         
  72.         if self.supported_ui_toolkits is not None and prop.gui_build and self.installed_ui_toolkits:
  73.             if self.default_ui_toolkit == 'qt3' and UI_TOOLKIT_QT4 in self.supported_ui_toolkits and UI_TOOLKIT_QT3 not in self.supported_ui_toolkits and INTERACTIVE_MODE in self.avail_modes:
  74.                 self.default_mode = INTERACTIVE_MODE
  75.                 self.default_ui_toolkit = 'none'
  76.             elif (UI_TOOLKIT_QT4 in self.supported_ui_toolkits and self.default_ui_toolkit == 'qt4' or UI_TOOLKIT_QT4 in self.installed_ui_toolkits or UI_TOOLKIT_QT3 in self.supported_ui_toolkits) and self.default_ui_toolkit == 'qt3' and UI_TOOLKIT_QT3 in self.installed_ui_toolkits:
  77.                 self.default_mode = GUI_MODE
  78.             elif self.default_ui_toolkit == 'qt3' and UI_TOOLKIT_QT3 not in self.supported_ui_toolkits:
  79.                 if UI_TOOLKIT_QT4 in self.supported_ui_toolkits and UI_TOOLKIT_QT4 in self.installed_ui_toolkits:
  80.                     self.default_ui_toolkit = 'qt4'
  81.                     self.default_mode = GUI_MODE
  82.                 elif INTERACTIVE_MODE in self.avail_modes:
  83.                     self.default_mode = INTERACTIVE_MODE
  84.                 elif NON_INTERACTIVE_MODE in self.avail_modes:
  85.                     self.default_mode = NON_INTERACTIVE_MODE
  86.                 else:
  87.                     log.error('%s cannot be run using Qt3 toolkit.' % self.mod)
  88.                     sys.exit(1)
  89.             elif self.default_ui_toolkit == 'qt4' and UI_TOOLKIT_QT4 not in self.supported_ui_toolkits:
  90.                 if UI_TOOLKIT_QT3 in self.supported_ui_toolkits and UI_TOOLKIT_QT3 in self.installed_ui_toolkits:
  91.                     self.default_ui_toolkit = 'qt3'
  92.                     self.default_mode = GUI_MODE
  93.                 elif INTERACTIVE_MODE in self.avail_modes:
  94.                     self.default_mode = INTERACTIVE_MODE
  95.                 elif NON_INTERACTIVE_MODE in self.avail_modes:
  96.                     self.default_mode = NON_INTERACTIVE_MODE
  97.                 else:
  98.                     log.error('%s cannot be run using Qt4 toolkit.' % self.mod)
  99.                     sys.exit(1)
  100.             
  101.         
  102.         self.mode = self.default_mode
  103.         if os.getuid() == 0 and not run_as_root_ok:
  104.             log.warn('%s should not be run as root/superuser.' % mod)
  105.         
  106.  
  107.     
  108.     def setUsage(self, include_flags = 0, extra_options = None, extra_notes = None, see_also_list = None):
  109.         if self.doc:
  110.             self.usage_data = [
  111.                 (self.doc, '', 'name', True)]
  112.         else:
  113.             self.usage_data = []
  114.         summary = [
  115.             'Usage:',
  116.             self.mod]
  117.         content = []
  118.         notes = []
  119.         if include_flags & USAGE_FLAG_DEVICE_ARGS == USAGE_FLAG_DEVICE_ARGS:
  120.             summary.append('[DEVICE_URI|PRINTER_NAME]')
  121.             content.append(utils.USAGE_ARGS)
  122.             content.append(utils.USAGE_DEVICE)
  123.             content.append(utils.USAGE_PRINTER)
  124.         
  125.         if self.avail_modes is not None and self.num_valid_modes > 1:
  126.             summary.append('[MODE]')
  127.             content.append(utils.USAGE_SPACE)
  128.             content.append(utils.USAGE_MODE)
  129.             if self.num_installed_ui_toolkits > 0:
  130.                 if GUI_MODE in self.avail_modes and prop.gui_build:
  131.                     content.append(utils.USAGE_GUI_MODE)
  132.                 
  133.             
  134.             if INTERACTIVE_MODE in self.avail_modes:
  135.                 content.append(utils.USAGE_INTERACTIVE_MODE)
  136.             
  137.             if NON_INTERACTIVE_MODE in self.avail_modes:
  138.                 content.append(utils.USAGE_NON_INTERACTIVE_MODE)
  139.             
  140.         
  141.         summary.append('[OPTIONS]')
  142.         content.append(utils.USAGE_SPACE)
  143.         content.append(utils.USAGE_OPTIONS)
  144.         if self.avail_modes is not None and GUI_MODE in self.avail_modes and self.supported_ui_toolkits is not None and self.num_supported_ui_toolkits > 0 and prop.gui_build and self.num_installed_ui_toolkits > 0:
  145.             if UI_TOOLKIT_QT3 in self.supported_ui_toolkits and UI_TOOLKIT_QT3 in self.installed_ui_toolkits:
  146.                 content.append(utils.USAGE_USE_QT3)
  147.             
  148.             if UI_TOOLKIT_QT4 in self.supported_ui_toolkits and UI_TOOLKIT_QT4 in self.installed_ui_toolkits:
  149.                 content.append(utils.USAGE_USE_QT4)
  150.             
  151.         
  152.         content.append(utils.USAGE_LOGGING1)
  153.         content.append(utils.USAGE_LOGGING2)
  154.         if include_flags & USAGE_FLAG_SUPRESS_G_DEBUG_FLAG != USAGE_FLAG_SUPRESS_G_DEBUG_FLAG:
  155.             content.append(utils.USAGE_LOGGING3)
  156.         
  157.         content.append(utils.USAGE_HELP)
  158.         if extra_options is not None:
  159.             for e in extra_options:
  160.                 content.append(e)
  161.             
  162.         
  163.         if include_flags & USAGE_FLAG_FILE_ARGS:
  164.             summary.append('[FILES]')
  165.         
  166.         if extra_notes is not None or notes:
  167.             content.append(utils.USAGE_SPACE)
  168.             content.append(utils.USAGE_NOTES)
  169.             for n in notes:
  170.                 content.append(n)
  171.             
  172.             if extra_notes is not None:
  173.                 for n in extra_notes:
  174.                     content.append(n)
  175.                 
  176.             
  177.         
  178.         if see_also_list is not None:
  179.             content.append(utils.USAGE_SPACE)
  180.             content.append(utils.USAGE_SEEALSO)
  181.             for s in see_also_list:
  182.                 content.append((s, '', 'seealso', False))
  183.             
  184.         
  185.         content.insert(0, (' '.join(summary), '', 'summary', True))
  186.         for c in content:
  187.             self.usage_data.append(c)
  188.         
  189.  
  190.     
  191.     def parseStdOpts(self, extra_params = None, extra_long_params = None, handle_device_printer = True, supress_g_debug_flag = False):
  192.         params = 'l:h'
  193.         if not supress_g_debug_flag:
  194.             params = ''.join([
  195.                 params,
  196.                 'g'])
  197.         
  198.         long_params = [
  199.             'logging=',
  200.             'help',
  201.             'help-rest',
  202.             'help-man',
  203.             'help-desc',
  204.             'debug',
  205.             'dbg']
  206.         if handle_device_printer:
  207.             params = ''.join([
  208.                 params,
  209.                 'd:p:P:'])
  210.             long_params.extend([
  211.                 'device=',
  212.                 'device-uri=',
  213.                 'printer=',
  214.                 'printer-name'])
  215.         
  216.         if self.num_valid_modes > 1:
  217.             if GUI_MODE in self.avail_modes and prop.gui_build:
  218.                 params = ''.join([
  219.                     params,
  220.                     'u'])
  221.                 long_params.extend([
  222.                     'gui',
  223.                     'ui'])
  224.             
  225.             if INTERACTIVE_MODE in self.avail_modes:
  226.                 params = ''.join([
  227.                     params,
  228.                     'i'])
  229.                 long_params.extend([
  230.                     'interactive',
  231.                     'text'])
  232.             
  233.             if NON_INTERACTIVE_MODE in self.avail_modes:
  234.                 params = ''.join([
  235.                     params,
  236.                     'n'])
  237.                 long_params.extend([
  238.                     'noninteractive',
  239.                     'non-interactive',
  240.                     'batch'])
  241.             
  242.         
  243.         if self.supported_ui_toolkits is not None and self.num_supported_ui_toolkits > 1 and prop.gui_build and self.avail_modes is not None and GUI_MODE in self.avail_modes:
  244.             if UI_TOOLKIT_QT3 in self.supported_ui_toolkits and UI_TOOLKIT_QT3 in self.installed_ui_toolkits:
  245.                 long_params.extend([
  246.                     'qt3',
  247.                     'use-qt3'])
  248.             
  249.             if UI_TOOLKIT_QT4 in self.supported_ui_toolkits and UI_TOOLKIT_QT4 in self.installed_ui_toolkits:
  250.                 long_params.extend([
  251.                     'qt4',
  252.                     'use-qt4'])
  253.             
  254.         
  255.         if extra_params is not None:
  256.             params = ''.join([
  257.                 params,
  258.                 extra_params])
  259.         
  260.         if extra_long_params is not None:
  261.             long_params.extend(extra_long_params)
  262.         
  263.         opts = None
  264.         show_usage = None
  265.         device_uri = None
  266.         printer_name = None
  267.         error_msg = []
  268.         mode = self.default_mode
  269.         if prop.gui_build:
  270.             ui_toolkit = self.default_ui_toolkit
  271.         else:
  272.             ui_toolkit = 'none'
  273.         lang = None
  274.         
  275.         try:
  276.             (opts, self.args) = getopt.getopt(sys.argv[1:], params, long_params)
  277.         except getopt.GetoptError:
  278.             e = None
  279.             error_msg = [
  280.                 e.msg]
  281.  
  282.         for o, a in opts:
  283.             if o in ('-d', '--device', '--device-uri'):
  284.                 device_uri = a
  285.                 continue
  286.             if o in ('-P', '-p', '--printer', '--printer-name'):
  287.                 printer_name = a
  288.                 continue
  289.             if o in ('-l', '--logging'):
  290.                 log_level = a.lower().strip()
  291.                 if not log.set_level(log_level):
  292.                     show_usage = 'text'
  293.                 
  294.             log.set_level(log_level)
  295.             if o in ('-g', '--debug', '--dbg'):
  296.                 log.set_level('debug')
  297.                 continue
  298.             if o in ('-u', '--gui', '--ui'):
  299.                 if self.avail_modes is not None and GUI_MODE in self.avail_modes and self.supported_ui_toolkits is not None and prop.gui_build:
  300.                     mode = GUI_MODE
  301.                 else:
  302.                     error_msg.append('Unable to enter GUI mode.')
  303.             prop.gui_build
  304.             if o in ('-i', '--interactive', '--text'):
  305.                 if self.avail_modes is not None and INTERACTIVE_MODE in self.avail_modes:
  306.                     mode = INTERACTIVE_MODE
  307.                     ui_toolkit = 'none'
  308.                 
  309.             INTERACTIVE_MODE in self.avail_modes
  310.             if o in ('-n', '--non-interactive', '--batch'):
  311.                 if self.avail_modes is not None and NON_INTERACTIVE_MODE in self.avail_modes:
  312.                     mode = NON_INTERACTIVE_MODE
  313.                     ui_toolkit = 'none'
  314.                 
  315.             NON_INTERACTIVE_MODE in self.avail_modes
  316.             if o in ('-h', '--help'):
  317.                 show_usage = 'text'
  318.                 continue
  319.             if o == '--help-rest':
  320.                 show_usage = 'rest'
  321.                 continue
  322.             if o == '--help-man':
  323.                 show_usage = 'man'
  324.                 continue
  325.             if o == '--help-desc':
  326.                 show_usage = 'desc'
  327.                 continue
  328.             if o in ('--qt3', '--use-qt3'):
  329.                 if self.avail_modes is not None and GUI_MODE in self.avail_modes:
  330.                     if self.supported_ui_toolkits is not None and UI_TOOLKIT_QT3 in self.supported_ui_toolkits and prop.gui_build and UI_TOOLKIT_QT3 in self.installed_ui_toolkits:
  331.                         mode = GUI_MODE
  332.                         ui_toolkit = 'qt3'
  333.                     else:
  334.                         error_msg.append('%s does not support Qt3. Unable to enter GUI mode.' % self.mod)
  335.                 
  336.             GUI_MODE in self.avail_modes
  337.             if o in ('--qt4', '--use-qt4'):
  338.                 if self.avail_modes is not None and GUI_MODE in self.avail_modes:
  339.                     if self.supported_ui_toolkits is not None and UI_TOOLKIT_QT4 in self.supported_ui_toolkits and prop.gui_build and UI_TOOLKIT_QT4 in self.installed_ui_toolkits:
  340.                         mode = GUI_MODE
  341.                         ui_toolkit = 'qt4'
  342.                     else:
  343.                         error_msg.append('%s does not support Qt4. Unable to enter GUI mode.' % self.mod)
  344.                 
  345.             GUI_MODE in self.avail_modes
  346.         
  347.         if error_msg:
  348.             show_usage = 'text'
  349.         
  350.         self.usage(show_usage, error_msg)
  351.         if show_usage is not None:
  352.             sys.exit(0)
  353.         
  354.         self.mode = mode
  355.         return (opts, device_uri, printer_name, mode, ui_toolkit, lang)
  356.  
  357.     
  358.     def showLanguages(self):
  359.         f = tui.Formatter()
  360.         f.header = ('Language Code', 'Alternate Name(s)')
  361.         for loc, ll in supported_locales.items():
  362.             f.add((ll[0], ', '.join(ll[1:])))
  363.         
  364.         f.output()
  365.  
  366.     
  367.     def usage(self, show_usage = 'text', error_msg = None):
  368.         if show_usage is None:
  369.             if not self.quiet:
  370.                 self.showTitle()
  371.             
  372.             return None
  373.         if show_usage == 'text':
  374.             self.showTitle()
  375.             log.info()
  376.         
  377.         if show_usage == 'desc':
  378.             print self.doc
  379.         else:
  380.             utils.format_text(self.usage_data, show_usage, self.title, self.mod, self.version)
  381.             if error_msg:
  382.                 for e in error_msg:
  383.                     log.error(e)
  384.                 
  385.                 sys.exit(1)
  386.             
  387.             sys.exit(0)
  388.             if show_usage == 'text':
  389.                 sys.exit(0)
  390.             
  391.  
  392.     
  393.     def showTitle(self, show_ver = True):
  394.         if not self.quiet:
  395.             log.info('')
  396.             if show_ver:
  397.                 log.info(log.bold('HP Linux Imaging and Printing System (ver. %s)' % prop.version))
  398.             else:
  399.                 log.info(log.bold('HP Linux Imaging and Printing System'))
  400.             log.info(log.bold('%s ver. %s' % (self.title, self.version)))
  401.             log.info('')
  402.             log.info('Copyright (c) 2001-9 Hewlett-Packard Development Company, LP')
  403.             log.info('This software comes with ABSOLUTELY NO WARRANTY.')
  404.             log.info('This is free software, and you are welcome to distribute it')
  405.             log.info('under certain conditions. See COPYING file for more details.')
  406.             log.info('')
  407.         
  408.  
  409.     
  410.     def getDeviceUri(self, device_uri = None, printer_name = None, back_end_filter = device.DEFAULT_BE_FILTER, filter = device.DEFAULT_FILTER, devices = None, restrict_to_installed_devices = True):
  411.         """ Validate passed in parameters, and, if in text mode, have user select desired device to use.
  412.             Used for tools that are device-centric and accept -d (and maybe also -p).
  413.             Use the filter(s) to restrict what constitute valid devices.
  414.  
  415.             Return the matching device URI based on:
  416.             1. Passed in device_uri if it is valid (filter passes)
  417.             2. Corresponding device_uri from the printer_name if it is valid (filter passes) ('*' means default printer)
  418.             3. User input from menu (based on bus and filter)
  419.  
  420.             device_uri and printer_name can both be specified if they correspond to the same device.
  421.  
  422.             Returns:
  423.                 device_uri|None
  424.                 (returns None if passed in device_uri is invalid or printer_name doesn't correspond to device_uri)
  425.         """
  426.         log.debug('getDeviceUri(%s, %s, %s, %s, , %s)' % (device_uri, printer_name, back_end_filter, filter, restrict_to_installed_devices))
  427.         log.debug('Mode=%s' % self.mode)
  428.         scan_uri_flag = False
  429.         if 'hpaio' in back_end_filter:
  430.             scan_uri_flag = True
  431.         
  432.         device_uri_ok = False
  433.         printer_name_ok = False
  434.         device_uri_ret = None
  435.         if devices is None:
  436.             devices = device.getSupportedCUPSDevices(back_end_filter, filter)
  437.             log.debug(devices)
  438.         
  439.         if device_uri is not None:
  440.             if device_uri in devices:
  441.                 device_uri_ok = True
  442.             elif restrict_to_installed_devices:
  443.                 log.error('Invalid device URI: %s' % device_uri)
  444.                 device_uri = None
  445.             else:
  446.                 device_uri_ok = True
  447.         
  448.         if printer_name is not None:
  449.             printers = device.getSupportedCUPSPrinterNames(back_end_filter, filter)
  450.             if printer_name in printers:
  451.                 printer_name_ok = True
  452.                 printer_name_device_uri = device.getDeviceURIByPrinterName(printer_name, scan_uri_flag)
  453.             else:
  454.                 log.error('Invalid printer name: %s' % printer_name)
  455.                 printer_name = None
  456.         
  457.         if device_uri is not None and printer_name is None and device_uri_ok:
  458.             device_uri_ret = device_uri
  459.         elif device_uri is not None and printer_name is not None:
  460.             if device_uri_ok and printer_name_ok:
  461.                 if device_uri == printer_name_device_uri:
  462.                     device_uri_ret = device_uri
  463.                 else:
  464.                     log.error('Printer name %s and device URI %s refer to different devices.' % (printer_name, device_uri))
  465.                     (printer_name, printer_name) = (None, None)
  466.             
  467.         elif device_uri is None and printer_name is not None and printer_name_ok:
  468.             device_uri_ret = device.getDeviceURIByPrinterName(printer_name, scan_uri_flag)
  469.         elif len(devices) == 1:
  470.             device_uri_ret = devices.keys()[0]
  471.             log.info('Using device: %s\n' % device_uri_ret)
  472.         
  473.         if device_uri_ret is None and self.mode in (INTERACTIVE_MODE, NON_INTERACTIVE_MODE) and len(devices):
  474.             device_uri_ret = tui.device_table(devices, scan_uri_flag)
  475.         
  476.         if device_uri_ret is not None:
  477.             user_conf.set('last_used', 'device_uri', device_uri_ret)
  478.         elif self.mode in (INTERACTIVE_MODE, NON_INTERACTIVE_MODE):
  479.             log.error('No device selected/specified or that supports this functionality.')
  480.             sys.exit(1)
  481.         else:
  482.             log.debug('No device selected/specified')
  483.         return device_uri_ret
  484.  
  485.     
  486.     def getPrinterName(self, printer_name, device_uri, back_end_filter = device.DEFAULT_BE_FILTER, filter = device.DEFAULT_FILTER):
  487.         """ Validate passed in parameters, and, if in text mode, have user select desired printer to use.
  488.             Used for tools that are printer queue-centric and accept -p (and maybe also -d).
  489.             Use the filter(s) to restrict what constitute valid printers.
  490.  
  491.             Return the matching printer_name based on:
  492.             1. Passed in printer_name if it is valid (filter passes) ('*' means default printer)
  493.             2. From single printer_name of corresponding passed in device_uri (filter passes)
  494.             3. User input from menu (CUPS printer list, filtered) [or if > 1 queue for device_uri]
  495.  
  496.             device_uri and printer_name can both be specified if they correspond to the same device.
  497.  
  498.             Returns:
  499.                 (printer_name|None, device_uri|None) (tuple)
  500.                 (returns None if passed in printer_name is invalid or device_uri doesn't correspond to printer_name)
  501.         """
  502.         log.debug('getPrinterName(%s, %s, %s, %s)' % (device_uri, printer_name, back_end_filter, filter))
  503.         log.debug('Mode=%s' % self.mode)
  504.         device_uri_ok = False
  505.         printer_name_ok = False
  506.         printer_name_ret = None
  507.         device_uri_ret = None
  508.         printers = device.getSupportedCUPSPrinterNames(back_end_filter, filter)
  509.         log.debug(printers)
  510.         if device_uri is not None:
  511.             devices = device.getSupportedCUPSDevices(back_end_filter, filter)
  512.             if device_uri in devices:
  513.                 device_uri_ok = True
  514.                 device_uri_ret = device_uri
  515.             else:
  516.                 log.error('Invalid device URI: %s' % device_uri)
  517.                 device_uri = None
  518.         
  519.         if printer_name is not None:
  520.             if printer_name == '*':
  521.                 cups = cups
  522.                 import prnt
  523.                 default_printer = cups.getDefaultPrinter()
  524.                 if default_printer is not None:
  525.                     printer_name_ret = default_printer
  526.                 else:
  527.                     log.error('CUPS default printer not set')
  528.                     printer_name = None
  529.             elif printer_name in printers:
  530.                 printer_name_ok = True
  531.                 device_uri_ret = device.getDeviceURIByPrinterName(printer_name)
  532.             else:
  533.                 log.error('Invalid printer name')
  534.                 printer_name = None
  535.         
  536.         if device_uri is not None and printer_name is None and device_uri_ok:
  537.             if len(devices[device_uri]) == 1:
  538.                 printer_name_ret = devices[device_uri][0]
  539.             
  540.         elif device_uri is not None and printer_name is not None:
  541.             if device_uri_ok and printer_name_ok:
  542.                 if device_uri == device_uri_ret:
  543.                     printer_name_ret = printer_name
  544.                 else:
  545.                     log.error('Printer name and device URI refer to different devices.')
  546.             
  547.         elif device_uri is None and printer_name is not None and printer_name_ok:
  548.             printer_name_ret = printer_name
  549.         elif len(printers) == 1:
  550.             printer_name_ret = printers[0]
  551.             log.info('Using printer: %s\n' % printer_name_ret)
  552.         
  553.         if printer_name_ret is None and self.mode in (INTERACTIVE_MODE, NON_INTERACTIVE_MODE) and len(printers):
  554.             printer_name_ret = tui.printer_table(printers)
  555.         
  556.         if printer_name_ret is not None and device_uri_ret is None:
  557.             device_uri_ret = device.getDeviceURIByPrinterName(printer_name_ret)
  558.         
  559.         if device_uri_ret is not None:
  560.             user_conf.set('last_used', 'device_uri', device_uri_ret)
  561.         
  562.         if printer_name_ret is not None:
  563.             user_conf.set('last_used', 'printer_name', printer_name_ret)
  564.         elif self.mode in (INTERACTIVE_MODE, NON_INTERACTIVE_MODE):
  565.             log.error('No printer selected/specified or that supports this functionality.')
  566.             sys.exit(1)
  567.         else:
  568.             log.debug('No printer selected/specified')
  569.         return (printer_name_ret, device_uri_ret)
  570.  
  571.     
  572.     def lockInstance(self, suffix = ''):
  573.         if suffix:
  574.             (ok, self.lock_file) = utils.lock_app('-'.join([
  575.                 self.mod,
  576.                 suffix]))
  577.         else:
  578.             (ok, self.lock_file) = utils.lock_app(self.mod)
  579.         if not ok:
  580.             sys.exit(1)
  581.         
  582.  
  583.     
  584.     def unlockInstance(self):
  585.         if self.lock_file is not None:
  586.             utils.unlock(self.lock_file)
  587.         
  588.  
  589.  
  590.